package com.ymatou.iapi.prodstock.testcase;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.apache.http.client.ClientProtocolException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.activitymgt.parameter.AddactivityBean;
import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.AgentPriceDto;
import com.shop2cn.iapi.agentproducts.parameter.CatalogDto;
import com.shop2cn.iapi.agentproducts.parameter.ImportAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.ProductDetailsDto;
import com.ymatou.iapi.godmch.parameter.AgentTypeVo;
import com.ymatou.iapi.godmch.parameter.listagentTypeBean;
import com.ymatou.iapi.liveseller.parameter.ActivityProductDto;
import com.ymatou.iapi.liveseller.parameter.CreateLiveActivityBean;
import com.ymatou.iapi.liveseller.parameter.CreateSellerLiveBean;
import com.ymatou.iapi.liveseller.parameter.LiveActivityDto;
import com.ymatou.iapi.prodstock.parameter.OrderReturnCatalogDto;
import com.ymatou.iapi.prodstock.parameter.OrderReturnCatalogDto.CatalogStockListDto;
import com.ymatou.iapi.prodstock.parameter.OrderReturnCatalogDtoV2;
import com.ymatou.iapi.prodstock.parameter.PCatalogListDto;
import com.ymatou.iapi.prodstock.parameter.PreOrderReduceCatalogDto;
import com.ymatou.iapi.prodstock.parameter.ReturnStockListForRefundBillBean;
import com.ymatou.iapi.prodstock.parameter.UpdateProductActivityStockTimeBean;
import com.ymatou.iapi.prodstock.service.ReturnStockListForRefundBillCall;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.productmongosync.service.EsCall;
import com.ymatou.iapi.productmongosync.service.MongocrudCall;
import com.ymatou.mq.admin.parameter.MessageListBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.ActivityCallService;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.AgentProductCallService;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.business.service.MqQueryCallService;
import com.ymttest.business.service.ProdStockCallService;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.business.service.ProductPriceCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.annotation.SqlMapperFactory;
import com.ymttest.database.annotation.product.IntergratedProductMapper;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.database.model.YmtCatalogsI;
import com.ymttest.database.mongo.jproduct.ActivityProductsWapper;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
import com.ymttest.database.sqlwapper.YmtCatalogsIWapper;
import com.ymttest.database.sqlwapper.YmtProductActivityStockWapper;
import com.ymttest.database.sqlwapper.YmtProductsIWapper;
import com.ymttest.database.sqlwapper.YmtProductsInActivityWapper;
import com.ymttest.utils.AgentUsers;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.MapUtil;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;

import cn.ymatou.activityadmin.service.CloseProductActivityCall;

public class Ts_ReturnStockListForRefundBill {
	// default data
	private static String sellerName = EnvSetup.getData("autotest_sellerName1");
	private static int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
	private static int sellerId1 = Integer.parseInt(EnvSetup.getData("productpriceSellerId"));
	private static int sellerId2 = Integer.parseInt(EnvSetup.getData("productsellerid"));

	private static YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
	private static ActivityProductsWapper activityProductsWapper = new ActivityProductsWapper();
	private static YmtProductActivityStockWapper ymtProductActivityStockWapper = new YmtProductActivityStockWapper();
	private static List<String> productlist;
	private static ReturnStockListForRefundBillCall returnStockListForRefundBillCall = new ReturnStockListForRefundBillCall();
	private static ReturnStockListForRefundBillBean returnStockListForRefundBillBean = new ReturnStockListForRefundBillBean();
    private static YmtCatalogsIWapper CIWapper=new YmtCatalogsIWapper();
	private static IntergratedProductMapper ipm = SqlMapperFactory.getIntergratedProductMapper();
	private static YmtProductsIWapper ymtProductsIWapper = new YmtProductsIWapper();

	//渠道商
	private static int rootUserId = AgentUsers.rootUserId;
	private static String rootUserName = "NickautoTest";
	//渠道商->代理商1
	private static int agentUserId1 = AgentUsers.agentUserId1;
	private static String agentUserName1 = "NickautoTest";
	//渠道商->代理商2
	private static int agentUserId2 = AgentUsers.agentUserId2;
	private static String agentUserName2 = "NickautoTest";

	//vip渠道
	private static int vipRootUserId = AgentUsers.vipRootUserId;
	private static String vipRootUserName = "NickautoTest";
	//vip渠道->代理
	private static int vipAgentUserId1 = AgentUsers.vipAgentUserId1;
	private static String vipAgentUserName1 = "dgsq408897016";
	//vip渠道->代理->代理
	private static int vipAgentUserId2 = AgentUsers.vipAgentUserId2;
	private static String vipAgentUserName2 = "NickautoTest";
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("退货退款返商品库存");
	}

	@Before
	public void caseUp() {
		productlist=new ArrayList<>();
	}

	@AfterClass
	public static void tearDown() throws Exception {
		ProductManagerCallServiceV2.updateActivityStock0(productlist);
		ProductManagerCallServiceV2.batchSetProductOffSale(productlist,sellerId);
		Logger.generateResult(returnStockListForRefundBillCall.getOpurl());
	}

	@After
	public void caseDown() throws ClientProtocolException, IOException, Exception {
		Logger.debug("下架商品");
		ProductManagerCallServiceV2.batchSetProductOffSale(productlist,sellerId);
		Logger.end();
	}     

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReturnStockListForRefundBill_001() {
		Logger.start(true, "普通现货商品,返库存");
		try{
			ProductManagerCallServiceV2.batchSetProductOffSale(ProductManagerCallServiceV2.getProducts(sellerId, 0),sellerId);
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存
			Integer catalogNum = 10000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			productlist.add(productId);
			YmtCatalogsI ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			String catalogId = ymtCatalog.getsCatalogId();
			int stockNum = 2;
			
			PCatalogListDto catalogListDto = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId, sellerId, 0, stockNum, 0, true);
			ProdStockCallService.checkReduceStock(catalogListDto,catalogNum-stockNum,0);
			
			
			//反库存
			long refundBillNo = getRefundBillNo();
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDto = new OrderReturnCatalogDto.CatalogStockListDto();
			catalogStockListDto.setRefundBillNo(refundBillNo);
			catalogStockListDto.setBuyerId(catalogListDto.getBuyerId());
			catalogStockListDto.setOrderId(catalogListDto.getPreOrderId());
			catalogStockListDto.setProductId(productId);
			catalogStockListDto.setCatalogId(catalogId);
			catalogStockListDto.setSellerId(sellerId);
			catalogStockListDto.setStockNum(stockNum-1);
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDtoNew = ProdStockCallService.ReturnStockListForRefundBill(catalogStockListDto);
			//check
			ProdStockCallService.checkReturnStockForBill(catalogStockListDtoNew, catalogNum-1, 0, true);
			
			//反库存 幂等
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDtoNew1 = ProdStockCallService.ReturnStockListForRefundBill(catalogStockListDto,true,true);
			//check
			ProdStockCallService.checkReturnStockForBill(catalogStockListDtoNew1, catalogNum-1, 0, true);
			
			//再次反库存
			catalogStockListDto.setRefundBillNo(refundBillNo+1);
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDtoNew2 = ProdStockCallService.ReturnStockListForRefundBill(catalogStockListDto);
			//check
			ProdStockCallService.checkReturnStockForBill(catalogStockListDtoNew2, catalogNum, 0, true);
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReturnStockListForRefundBill_002() {
		Logger.start(true, "普通现货商品,已删除规格不能扣减库存");
		try{
			ProductManagerCallServiceV2.batchSetProductOffSale(ProductManagerCallServiceV2.getProducts(sellerId, 0),sellerId);
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存
			Integer catalogNum = 10000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			productlist.add(productId);
			YmtCatalogsI ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			String catalogId = ymtCatalog.getsCatalogId();
			int stockNum = 2;
			
			 //已删除
			CIWapper.updateiActionByCatalogId(-1, ymtCatalog.getsCatalogId());
			//同步monogo、es
			EsCall esCall=new EsCall();
			MongocrudCall mongoCall=new MongocrudCall();
			esCall.callAndGetReturnData(MapUtil.hashMap("ProductId",productId,"ActionType","ModifyProduct","TransactionId",TestDataManager.getRandomIntNum(5)));
			mongoCall.callAndGetReturnData(MapUtil.hashMap("ProductId",productId,"ActionType","ModifyProduct","TransactionId",TestDataManager.getRandomIntNum(5)));
			
			PCatalogListDto catalogListDto = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId, sellerId, 0, stockNum, 0, false);
			ProdStockCallService.checkReduceStock(catalogListDto,catalogNum,0,false);
			
			
			//反库存
			long refundBillNo = getRefundBillNo();
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDto = new OrderReturnCatalogDto.CatalogStockListDto();
			catalogStockListDto.setRefundBillNo(refundBillNo);
			catalogStockListDto.setBuyerId(catalogListDto.getBuyerId());
			catalogStockListDto.setOrderId(catalogListDto.getPreOrderId());
			catalogStockListDto.setProductId(productId);
			catalogStockListDto.setCatalogId(catalogId);
			catalogStockListDto.setSellerId(sellerId);
			catalogStockListDto.setStockNum(stockNum-1);
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDtoNew = ProdStockCallService.ReturnStockListForRefundBill(catalogStockListDto);
			//check
			ProdStockCallService.checkReturnStockForBill(catalogStockListDtoNew, catalogNum, 0, false);
			
			//反库存 幂等
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDtoNew1 = ProdStockCallService.ReturnStockListForRefundBill(catalogStockListDto,true,true);
			//check
			ProdStockCallService.checkReturnStockForBill(catalogStockListDtoNew1, catalogNum, 0, false);
			
			//再次反库存
			catalogStockListDto.setRefundBillNo(refundBillNo);
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDtoNew2 = ProdStockCallService.ReturnStockListForRefundBill(catalogStockListDto);
			//check
			ProdStockCallService.checkReturnStockForBill(catalogStockListDtoNew2, catalogNum, 0, false);
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReturnStockListForRefundBill_003() {
		Logger.start(true, "普通现货商品,删除规格返库存");
		try{
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存
			Integer catalogNum = 10000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			productlist.add(productId);
			YmtCatalogsI ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			String catalogId = ymtCatalog.getsCatalogId();
			int stockNum = 2;
			
			PCatalogListDto catalogListDto = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId, sellerId, 0, stockNum, 0, true);
			ProdStockCallService.checkReduceStock(catalogListDto,catalogNum-stockNum,0);
			
			String catalogsId = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(0).getsCatalogId();
			//modify product and on sale 
//			Map<String, Object> updateMap = MapUtil.hashMap("LoginID", sellerName, "UserID", sellerId,
//															"Product->sProductId",productId,"ProductID",productId,
//															"Product->OnSaleType",0,	// 在售类型    Old = -1,  Immediately = 0,    SpecialTime = 1,   OffSale = 2,
//															"Product->Catalogs[2]->CatalogId",catalogsId);
//
//			String fileName = "changenewproductinfocalltpl_001.json";
//			new ChangeNewProductInfoCall().callAndGetReturnData(fileName,updateMap);
			//反库存
			long refundBillNo = getRefundBillNo();
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDto = new OrderReturnCatalogDto.CatalogStockListDto();
			catalogStockListDto.setRefundBillNo(refundBillNo);
			catalogStockListDto.setBuyerId(catalogListDto.getBuyerId());
			catalogStockListDto.setOrderId(catalogListDto.getPreOrderId());
			catalogStockListDto.setProductId(productId);
			catalogStockListDto.setCatalogId(catalogId);
			catalogStockListDto.setSellerId(sellerId);
			catalogStockListDto.setStockNum(stockNum-1);
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDtoNew = ProdStockCallService.ReturnStockListForRefundBill(catalogStockListDto);
			//check
			ProdStockCallService.checkReturnStockForBill(catalogStockListDtoNew, catalogNum-1, 0, true);
			
			//反库存 幂等
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDtoNew1 = ProdStockCallService.ReturnStockListForRefundBill(catalogStockListDto,true,true);
			//check
			ProdStockCallService.checkReturnStockForBill(catalogStockListDtoNew1, catalogNum-1, 0, true);
			
			//再次反库存
			catalogStockListDto.setRefundBillNo(refundBillNo+1);
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDtoNew2 = ProdStockCallService.ReturnStockListForRefundBill(catalogStockListDto);
			//check
			ProdStockCallService.checkReturnStockForBill(catalogStockListDtoNew2, catalogNum, 0, true);
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReturnStockListForRefundBill_004() {
		Logger.start(true, "活动商品,没有限购,返库存");
		try {
			String productId = ProductPriceCallService.getProdPriceWithActivity_NewBuyerAndNoIsolation(sellerId).getProductId();
			productlist.add(productId);
			YmtCatalogsI ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			String catalogId = ymtCatalog.getsCatalogId();
			int catalogNum = ymtCatalog.getiNum();
			int stockNum = 2;
			int actNum = ymtProductActivityStockWapper.selectByCatalogId(catalogId).getIstocknum();
			
			int aid = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("aid").toString());
			
			// 扣库存
			PCatalogListDto catalogListDto = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId,
					sellerId, aid, stockNum, 0, true);
			// check
			ProdStockCallService.checkReduceStock(catalogListDto, catalogNum, actNum-stockNum);
			
			
			//反库存
			long refundBillNo = getRefundBillNo();
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDto = new OrderReturnCatalogDto.CatalogStockListDto();
			catalogStockListDto.setRefundBillNo(refundBillNo);
			catalogStockListDto.setBuyerId(catalogListDto.getBuyerId());
			catalogStockListDto.setOrderId(catalogListDto.getPreOrderId());
			catalogStockListDto.setProductId(productId);
			catalogStockListDto.setCatalogId(catalogId);
			catalogStockListDto.setActivityId(aid);
			catalogStockListDto.setSellerId(sellerId);
			catalogStockListDto.setStockNum(stockNum-1);
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDtoNew = ProdStockCallService.ReturnStockListForRefundBill(catalogStockListDto);
			//check
			ProdStockCallService.checkReturnStockForBill(catalogStockListDtoNew, catalogNum, actNum-1, true);
			
			
			//反库存 幂等
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDtoNew1 = ProdStockCallService.ReturnStockListForRefundBill(catalogStockListDto,true,true);
			//check
			ProdStockCallService.checkReturnStockForBill(catalogStockListDtoNew1, catalogNum, actNum-1, true);
		
			//再次反库存
			catalogStockListDto.setRefundBillNo(refundBillNo+1);
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDtoNew2 = ProdStockCallService.ReturnStockListForRefundBill(catalogStockListDto);
			//check
			ProdStockCallService.checkReturnStockForBill(catalogStockListDtoNew2, catalogNum, actNum, true);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReturnStockListForRefundBill_005() {
		Logger.start(true, "活动商品,活动限购,扣减库存,返库存,扣库存");
		try {
			int buyerId = Math.abs(TestDataManager.getRandomIntNum(4));
			String productId = ProductPriceCallService.getProdPriceWithActivity_NewBuyerAndNoIsolation(sellerId).getProductId();
			productlist.add(productId);
			YmtCatalogsI ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			String catalogId = ymtCatalog.getsCatalogId();
			int catalogNum = ymtCatalog.getiNum();
			int stockNum = 2;
			int actNum = ymtProductActivityStockWapper.selectByCatalogId(catalogId).getIstocknum();
			
			int aid = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("aid").toString());
			
			//修改活动限购数量 商品限购
			ProdStockCallService.updateActivityLimit(aid, 0, 3);
			
			// 扣库存
			PCatalogListDto catalogListDto = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId,sellerId, aid, stockNum, 0,buyerId, true);
			// check
			ProdStockCallService.checkReduceStock(catalogListDto, catalogNum, actNum-stockNum);
			
			//反库存
			long refundBillNo = getRefundBillNo();
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDto = new OrderReturnCatalogDto.CatalogStockListDto();
			catalogStockListDto.setRefundBillNo(refundBillNo);
			catalogStockListDto.setBuyerId(catalogListDto.getBuyerId());
			catalogStockListDto.setOrderId(catalogListDto.getPreOrderId());
			catalogStockListDto.setProductId(productId);
			catalogStockListDto.setCatalogId(catalogId);
			catalogStockListDto.setActivityId(aid);
			catalogStockListDto.setSellerId(sellerId);
			catalogStockListDto.setStockNum(stockNum);
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDtoNew = ProdStockCallService.ReturnStockListForRefundBill(catalogStockListDto);
			//check
			ProdStockCallService.checkReturnStockForBill(catalogStockListDtoNew, catalogNum, actNum, true);
			
			
			//该用户再下单
			// 扣库存
			PCatalogListDto catalogListDto1 = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId,sellerId, aid, stockNum, 0,buyerId, true);
			// check
			ProdStockCallService.checkReduceStock(catalogListDto1, catalogNum, actNum-stockNum);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReturnStockListForRefundBill_006() {
		Logger.start(true, "活动商品,活动商品限购,扣减库存,返库存,扣库存");
		try {
			int buyerId = Math.abs(TestDataManager.getRandomIntNum(4));
			String productId = ProductPriceCallService.getProdPriceWithActivity_NewBuyerAndNoIsolation(sellerId).getProductId();
			productlist.add(productId);
			YmtCatalogsI ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			String catalogId = ymtCatalog.getsCatalogId();
			int catalogNum = ymtCatalog.getiNum();
			int stockNum = 2;
			int actNum = ymtProductActivityStockWapper.selectByCatalogId(catalogId).getIstocknum();
			
			int aid = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("aid").toString());
			
			//修改活动限购数量 商品限购
			ProdStockCallService.updateActivityLimit(aid, 1, 3);
			
			// 扣库存
			PCatalogListDto catalogListDto = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId,sellerId, aid, stockNum, 0,buyerId, true);
			// check
			ProdStockCallService.checkReduceStock(catalogListDto, catalogNum, actNum-stockNum);
			
			//反库存
			long refundBillNo = getRefundBillNo();
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDto = new OrderReturnCatalogDto.CatalogStockListDto();
			catalogStockListDto.setRefundBillNo(refundBillNo);
			catalogStockListDto.setBuyerId(catalogListDto.getBuyerId());
			catalogStockListDto.setOrderId(catalogListDto.getPreOrderId());
			catalogStockListDto.setProductId(productId);
			catalogStockListDto.setCatalogId(catalogId);
			catalogStockListDto.setActivityId(aid);
			catalogStockListDto.setSellerId(sellerId);
			catalogStockListDto.setStockNum(stockNum);
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDtoNew = ProdStockCallService.ReturnStockListForRefundBill(catalogStockListDto);
			//check
			ProdStockCallService.checkReturnStockForBill(catalogStockListDtoNew, catalogNum, actNum, true);
			
			//该用户再下单
			// 扣库存
			PCatalogListDto catalogListDto1 = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId,sellerId, aid, stockNum, 0,buyerId, true);
			// check
			ProdStockCallService.checkReduceStock(catalogListDto1, catalogNum, actNum-stockNum);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReturnStockListForRefundBill_007() {
		Logger.start(true, "活动商品,扣减库存,活动结束返库存");
		try {
			int buyerId = Math.abs(TestDataManager.getRandomIntNum(4));
			String productId = ProductPriceCallService.getProdPriceWithActivity_NewBuyerAndNoIsolation(sellerId).getProductId();
			productlist.add(productId);
			YmtCatalogsI ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			String catalogId = ymtCatalog.getsCatalogId();
			int catalogNum = ymtCatalog.getiNum();
			int reduceNum = 2;
			int actNum = ymtProductActivityStockWapper.selectByCatalogId(catalogId).getIstocknum();
			int aid = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("aid").toString());

			int stockNum=2;
			// 扣库存
			PCatalogListDto catalogListDto = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId,sellerId, aid, stockNum, 0,buyerId, true);
			// check
			ProdStockCallService.checkReduceStock(catalogListDto, catalogNum, actNum-stockNum);
			
			//结束活动
			int inaid = new YmtProductsInActivityWapper().selectByProductIdAndActivityId(productId, aid).getIproductinactivityid();
			new CloseProductActivityCall().closeProductInActivity(Arrays.asList(inaid));
			YMTDateUtil.waitTime(5);
			int catalogNumNew = ymtCatalogsIWapper.selectCatalogsByCatalogId(catalogId).getiNum();
			
			//反库存 返共享库存
			long refundBillNo = getRefundBillNo();
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDto = new OrderReturnCatalogDto.CatalogStockListDto();
			catalogStockListDto.setRefundBillNo(refundBillNo);
			catalogStockListDto.setBuyerId(catalogListDto.getBuyerId());
			catalogStockListDto.setOrderId(catalogListDto.getPreOrderId());
			catalogStockListDto.setProductId(productId);
			catalogStockListDto.setCatalogId(catalogId);
			catalogStockListDto.setActivityId(aid);
			catalogStockListDto.setSellerId(sellerId);
			catalogStockListDto.setStockNum(stockNum);
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDtoNew = ProdStockCallService.ReturnStockListForRefundBill(catalogStockListDto);
			
			//check
			catalogStockListDtoNew.setActivityId(0);
			ProdStockCallService.checkReturnStockForBill(catalogStockListDtoNew, catalogNumNew+stockNum, 0, true);

			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReturnStockListForRefundBill_008() {
		Logger.start(true, "普通FBX商品,扣减库存,反库存");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// fbx设置商品库存 sku
			Integer catalogNum = 10000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			productlist.add(productId);
			
			//修改catalogType=2 FBX
			new YmtProductsIWapper().updateCatalogTypeByProductId(productId, 2);
			new YmtCatalogsIWapper().updateCatalogTypeByProductId(productId, 2);
			
			YmtCatalogsI ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			String catalogId = ymtCatalog.getsCatalogId();
			int stockNum = 2;
			
			//扣库存
			PCatalogListDto catalogListDto = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId, sellerId, 0, stockNum, 2, true);
			//check
			ProdStockCallService.checkReduceStock(catalogListDto,catalogNum-stockNum,0);
			
			//反库存
			long refundBillNo = getRefundBillNo();
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDto = new OrderReturnCatalogDto.CatalogStockListDto();
			catalogStockListDto.setRefundBillNo(refundBillNo);
			catalogStockListDto.setBuyerId(catalogListDto.getBuyerId());
			catalogStockListDto.setOrderId(catalogListDto.getPreOrderId());
			catalogStockListDto.setProductId(productId);
			catalogStockListDto.setCatalogId(catalogId);
			catalogStockListDto.setSellerId(sellerId);
			catalogStockListDto.setStockNum(stockNum);
			catalogStockListDto.setCatalogType(2);
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDtoNew = ProdStockCallService.ReturnStockListForRefundBill(catalogStockListDto);
			//check
			ProdStockCallService.checkReturnStockForBill(catalogStockListDtoNew, catalogNum, 0, true);
			
			//反库存 幂等
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDtoNew1 = ProdStockCallService.ReturnStockListForRefundBill(catalogStockListDto,true,true);
			//check
			ProdStockCallService.checkReturnStockForBill(catalogStockListDtoNew1, catalogNum, 0, true);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	@Deprecated
	public void Tc_ReturnStockListForRefundBill_009() {
		Logger.start(true, "FBX活动商品,没有限购,扣库存,返库存");
		try {
			int buyerId = Math.abs(TestDataManager.getRandomIntNum(4));
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存
			Integer catalogNum = 10000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建商品:" + productId);
			Integer activityId = ActivityCallService.createIsolationActivityInProcess();
			Logger.comment("创建交易隔离活动:" + activityId);
			List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			// 活动库存
			int actNum = 10;
			Logger.debug(catalogs);
			Thread.sleep(5000);
			//ProductManagerCallServiceV2.addActivity(productId, sellerId, catalogs, activityId.toString(), actNum);
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, actNum,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			ymtProductActivityStockWapper.updateStartTimeByProductId(productId, YMTDateUtil.getBeforeOrNextSecond(-300, YMTDateUtil.YMDHMS));
			String catalogId = catalogs.get(0);
			
			//修改catalogType=2 FBX
			new YmtProductsIWapper().updateCatalogTypeByProductId(productId, 2);
			new YmtCatalogsIWapper().updateCatalogTypeByProductId(productId, 2);
			
			int stockNum = 2;
			
			
			//扣库存
			PCatalogListDto catalogListDto = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId, sellerId, activityId, stockNum, 2, true);
			//check
			ProdStockCallService.checkReduceStock(catalogListDto,catalogNum-actNum,actNum-stockNum);
			
			//反库存
			long refundBillNo = getRefundBillNo();
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDto = new OrderReturnCatalogDto.CatalogStockListDto();
			catalogStockListDto.setRefundBillNo(refundBillNo);
			catalogStockListDto.setBuyerId(catalogListDto.getBuyerId());
			catalogStockListDto.setOrderId(catalogListDto.getPreOrderId());
			catalogStockListDto.setProductId(productId);
			catalogStockListDto.setCatalogId(catalogId);
			catalogStockListDto.setSellerId(sellerId);
			catalogStockListDto.setStockNum(stockNum);
			catalogStockListDto.setActivityId(activityId);
			catalogStockListDto.setCatalogType(2);
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDtoNew = ProdStockCallService.ReturnStockListForRefundBill(catalogStockListDto);
			//check
			ProdStockCallService.checkReturnStockForBill(catalogStockListDtoNew, catalogNum-actNum, actNum, true);
			
			//反库存 幂等
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDtoNew1 = ProdStockCallService.ReturnStockListForRefundBill(catalogStockListDto,true,true);
			//check
			ProdStockCallService.checkReturnStockForBill(catalogStockListDtoNew1, catalogNum-actNum, actNum, true);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReturnStockListForRefundBill_010() {
		Logger.start(true, "FBX活动商品,活动限购,扣减库存,反库存 ");
		try {
			int buyerId = Math.abs(TestDataManager.getRandomIntNum(4));
			String productId = ProductPriceCallService.getProdPriceWithActivity_NewBuyerAndNoIsolation(sellerId).getProductId();
			productlist.add(productId);
			YmtCatalogsI ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			String catalogId = ymtCatalog.getsCatalogId();
			int catalogNum = ymtCatalog.getiNum();
			int stockNum = 2;
			int actNum = ymtProductActivityStockWapper.selectByCatalogId(catalogId).getIstocknum();
			
			int aid = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("aid").toString());
			
			productlist.add(productId);
			//修改catalogType=2 FBX
			new YmtProductsIWapper().updateCatalogTypeByProductId(productId, 2);
			new YmtCatalogsIWapper().updateCatalogTypeByProductId(productId, 2);
			
			
			//修改活动限购数量 商品限购
			ProdStockCallService.updateActivityLimit(aid, 0, 3);
			
			//扣库存
			PCatalogListDto catalogListDto = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId,sellerId, aid, stockNum, 2,buyerId, true);
			//check
			ProdStockCallService.checkReduceStock(catalogListDto, catalogNum, actNum-stockNum);
			
			//反库存
			long refundBillNo = getRefundBillNo();
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDto = new OrderReturnCatalogDto.CatalogStockListDto();
			catalogStockListDto.setRefundBillNo(refundBillNo);
			catalogStockListDto.setBuyerId(catalogListDto.getBuyerId());
			catalogStockListDto.setOrderId(catalogListDto.getPreOrderId());
			catalogStockListDto.setProductId(productId);
			catalogStockListDto.setCatalogId(catalogId);
			catalogStockListDto.setActivityId(aid);
			catalogStockListDto.setSellerId(sellerId);
			catalogStockListDto.setStockNum(stockNum);
			catalogStockListDto.setCatalogType(2);
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDtoNew = ProdStockCallService.ReturnStockListForRefundBill(catalogStockListDto);
			//check
			ProdStockCallService.checkReturnStockForBill(catalogStockListDtoNew, catalogNum, actNum, true);
			
			//该用户再下单
			// 扣库存
			PCatalogListDto catalogListDto1 = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId,sellerId, aid, stockNum, 2,buyerId, true);
			// check
			ProdStockCallService.checkReduceStock(catalogListDto1, catalogNum, actNum-stockNum);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReturnStockListForRefundBill_011() {
		Logger.start(true, "FBX活动商品,活动商品限购,扣减库存,反库存 ");
		try {
			int buyerId = Math.abs(TestDataManager.getRandomIntNum(4));
			String productId = ProductPriceCallService.getProdPriceWithActivity_NewBuyerAndNoIsolation(sellerId).getProductId();
			productlist.add(productId);
			//修改catalogType=2 FBX
			new YmtProductsIWapper().updateCatalogTypeByProductId(productId, 2);
			new YmtCatalogsIWapper().updateCatalogTypeByProductId(productId, 2);
			
			YmtCatalogsI ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			String catalogId = ymtCatalog.getsCatalogId();
			int catalogNum = ymtCatalog.getiNum();
			int stockNum = 2;
			
			int actNum = ymtProductActivityStockWapper.selectByCatalogId(catalogId).getIstocknum();
			int aid = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("aid").toString());
			
			//修改活动限购数量 商品限购
			ProdStockCallService.updateActivityLimit(aid, 1, 3);
			
			//扣库存
			PCatalogListDto catalogListDto = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId,sellerId, aid, stockNum, 2,buyerId, true);
			//check
			ProdStockCallService.checkReduceStock(catalogListDto, catalogNum, actNum-stockNum);
			
			//反库存
			long refundBillNo = getRefundBillNo();
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDto = new OrderReturnCatalogDto.CatalogStockListDto();
			catalogStockListDto.setRefundBillNo(refundBillNo);
			catalogStockListDto.setBuyerId(catalogListDto.getBuyerId());
			catalogStockListDto.setOrderId(catalogListDto.getPreOrderId());
			catalogStockListDto.setProductId(productId);
			catalogStockListDto.setCatalogId(catalogId);
			catalogStockListDto.setActivityId(aid);
			catalogStockListDto.setSellerId(sellerId);
			catalogStockListDto.setStockNum(stockNum);
			catalogStockListDto.setCatalogType(2);
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDtoNew = ProdStockCallService.ReturnStockListForRefundBill(catalogStockListDto);
			//check
			ProdStockCallService.checkReturnStockForBill(catalogStockListDtoNew, catalogNum, actNum, true);
			
			//该用户再下单
			// 扣库存
			PCatalogListDto catalogListDto1 = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId,sellerId, aid, stockNum, 2,buyerId, true);
			// check
			ProdStockCallService.checkReduceStock(catalogListDto1, catalogNum, actNum-stockNum);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReturnStockListForRefundBill_012() {
		Logger.start(true, "FBX活动商品,没有限购,扣库存,活动结束,返库存");
		try {
			String productId = ProductPriceCallService.getProdPriceWithActivity_NewBuyerAndNoIsolation(sellerId).getProductId();
			productlist.add(productId);
			//修改catalogType=2 FBX
			new YmtProductsIWapper().updateCatalogTypeByProductId(productId, 2);
			new YmtCatalogsIWapper().updateCatalogTypeByProductId(productId, 2);
			
			YmtCatalogsI ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			String catalogId = ymtCatalog.getsCatalogId();
			int catalogNum = ymtCatalog.getiNum();
			int stockNum = 2;
			
			int actNum = ymtProductActivityStockWapper.selectByCatalogId(catalogId).getIstocknum();
			int aid = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("aid").toString());
			
			//扣库存
			PCatalogListDto catalogListDto = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId, sellerId, aid, stockNum, 2, true);
			//check
			ProdStockCallService.checkReduceStock(catalogListDto,catalogNum,actNum-stockNum);
			
			//结束活动
			int inaid = new YmtProductsInActivityWapper().selectByProductIdAndActivityId(productId, aid).getIproductinactivityid();
			new CloseProductActivityCall().closeProductInActivity(Arrays.asList(inaid));
			YMTDateUtil.waitTime(5);
			int catalogNumNew = ymtCatalogsIWapper.selectCatalogsByCatalogId(catalogId).getiNum();
			
			//反库存
			long refundBillNo = getRefundBillNo();
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDto = new OrderReturnCatalogDto.CatalogStockListDto();
			catalogStockListDto.setRefundBillNo(refundBillNo);
			catalogStockListDto.setBuyerId(catalogListDto.getBuyerId());
			catalogStockListDto.setOrderId(catalogListDto.getPreOrderId());
			catalogStockListDto.setProductId(productId);
			catalogStockListDto.setCatalogId(catalogId);
			catalogStockListDto.setSellerId(sellerId);
			catalogStockListDto.setStockNum(stockNum);
			catalogStockListDto.setActivityId(aid);
			catalogStockListDto.setCatalogType(2);
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDtoNew = ProdStockCallService.ReturnStockListForRefundBill(catalogStockListDto);
		
			//check
			catalogStockListDtoNew.setActivityId(0);
			catalogStockListDtoNew.setCatalogType(0);
			ProdStockCallService.checkReturnStockForBill(catalogStockListDtoNew, catalogNumNew+stockNum, 0, true);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	public void Tc_ReturnStockListForRefundBill_013() {
		Logger.start(true, "活动商品,活动限购,扣减库存,返库存,多个订单");
		try {

			String productId1 = ProductPriceCallService.getProdPriceWithActivity_NewBuyerAndNoIsolation(sellerId).getProductId();
			//商品A
			productlist.add(productId1);
			YmtCatalogsI ymtCatalog1 = ymtCatalogsIWapper.selectCatalogsByProductId(productId1).get(0);
			String catalogId1 = ymtCatalog1.getsCatalogId();
			int catalogNum1 = ymtCatalog1.getiNum();
			int reduceNum1 = 1;
			int actNum1 = ymtProductActivityStockWapper.selectByCatalogId(catalogId1).getIstocknum();
			
			//商品B1
			String productId2 = ProductPriceCallService.getProdPriceWithActivity_NewBuyerAndNoIsolation(sellerId).getProductId();
			productlist.add(productId2);
			YmtCatalogsI ymtCatalog2 = ymtCatalogsIWapper.selectCatalogsByProductId(productId2).get(0);
			String catalogId2 = ymtCatalog2.getsCatalogId();
			int catalogNum2 = ymtCatalog2.getiNum();
			int reduceNum2 = 1;
			int actNum2 = ymtProductActivityStockWapper.selectByCatalogId(catalogId2).getIstocknum();

			//修改活动限购数量 商品限购2个
			int aid = Integer.parseInt(activityProductsWapper.getByProdId(productId1).get("aid").toString());
			ProdStockCallService.updateActivityLimit(aid, 0, 2);

			////////////////////////////////////////////////////////////////////////////////////////////////////
			// 扣库存
			PCatalogListDto catalogListDto3 = new PCatalogListDto();
			catalogListDto3.setProductId(productId1);
			catalogListDto3.setCatalogId(catalogId1);
			catalogListDto3.setSellerId(sellerId);
			catalogListDto3.setActivityId(aid);
			catalogListDto3.setBuyCount(reduceNum1);
			
			PCatalogListDto catalogListDto4 = new PCatalogListDto();
			catalogListDto4.setProductId(productId2);
			catalogListDto4.setCatalogId(catalogId2);
			catalogListDto4.setSellerId(sellerId);
			catalogListDto4.setActivityId(aid);
			catalogListDto4.setBuyCount(reduceNum2);
			
			
			ProdStockCallService.ReduceStockListForPreOrder(Arrays.asList(catalogListDto3,catalogListDto4), true, false);
			// check
			ProdStockCallService.checkReduceStock(catalogListDto3, catalogNum1, actNum1-reduceNum1);
			ProdStockCallService.checkReduceStock(catalogListDto4, catalogNum2, actNum2-reduceNum2);
	
			
			////////////////////////////////////////////////////////////////////////////////////////////////////
			//多个订单返
			CatalogStockListDto catalogStockListDto1 = new OrderReturnCatalogDto.CatalogStockListDto();
			catalogStockListDto1.setBuyerId(catalogListDto3.getBuyerId());
			catalogStockListDto1.setOrderId(catalogListDto3.getPreOrderId());
			catalogStockListDto1.setProductId(catalogListDto3.getProductId());
			catalogStockListDto1.setCatalogId(catalogListDto3.getCatalogId());
			catalogStockListDto1.setActivityId(catalogListDto3.getActivityId());
			catalogStockListDto1.setSellerId(sellerId);
			catalogStockListDto1.setStockNum(catalogListDto3.getBuyCount());
			
			CatalogStockListDto catalogStockListDto2 = new OrderReturnCatalogDto.CatalogStockListDto();
			catalogStockListDto2.setBuyerId(catalogListDto4.getBuyerId());
			catalogStockListDto2.setOrderId(catalogListDto4.getPreOrderId());
			catalogStockListDto2.setProductId(catalogListDto4.getProductId());
			catalogStockListDto2.setCatalogId(catalogListDto4.getCatalogId());
			catalogStockListDto2.setActivityId(catalogListDto4.getActivityId());
			catalogStockListDto2.setSellerId(sellerId);
			catalogStockListDto2.setStockNum(catalogListDto4.getBuyCount());
			
			ProdStockCallService.ReturnStockListForRefundBill(Arrays.asList(catalogStockListDto1,catalogStockListDto2));
			//check
			ProdStockCallService.checkReturnStockForBill(catalogStockListDto1, catalogNum1, actNum1, true);
			ProdStockCallService.checkReturnStockForBill(catalogStockListDto2, catalogNum2, actNum2, true);

			//幂等
			ProdStockCallService.ReturnStockListForRefundBill(Arrays.asList(catalogStockListDto1,catalogStockListDto2),true,true);
			ProdStockCallService.checkReturnStockForBill(catalogStockListDto1, catalogNum1, actNum1, true);
			ProdStockCallService.checkReturnStockForBill(catalogStockListDto2, catalogNum2, actNum2, true);
			
			
			////////////////////////////////////////////////////////////////////////////////////////////////////
			//在下单 //重新生成订单号
			catalogListDto3.setPreOrderId(0);
			catalogListDto4.setPreOrderId(0);
			ProdStockCallService.ReduceStockListForPreOrder(Arrays.asList(catalogListDto3,catalogListDto4), true, false);
			// check
			ProdStockCallService.checkReduceStock(catalogListDto3, catalogNum1, actNum1-reduceNum1);
			ProdStockCallService.checkReduceStock(catalogListDto4, catalogNum2, actNum2-reduceNum2);
			
			//一个一个返
			catalogStockListDto2.setRefundBillNo(0);
			catalogStockListDto2.setBuyerId(catalogListDto4.getBuyerId());
			catalogStockListDto2.setOrderId(catalogListDto4.getPreOrderId());
			catalogStockListDto2.setProductId(catalogListDto4.getProductId());
			catalogStockListDto2.setCatalogId(catalogListDto4.getCatalogId());
			catalogStockListDto2.setActivityId(catalogListDto4.getActivityId());
			catalogStockListDto2.setSellerId(sellerId);
			catalogStockListDto2.setStockNum(catalogListDto4.getBuyCount());
			ProdStockCallService.ReturnStockListForRefundBill(Arrays.asList(catalogStockListDto2));
			//check
			ProdStockCallService.checkReturnStockForBill(catalogStockListDto2, catalogNum1, actNum1, true);
			
			//幂等
			ProdStockCallService.ReturnStockListForRefundBill(Arrays.asList(catalogStockListDto2),true,true);
			ProdStockCallService.checkReturnStockForBill(catalogStockListDto2, catalogNum1, actNum1, true);
			
			
			
			catalogStockListDto1.setRefundBillNo(0);
			catalogStockListDto1.setBuyerId(catalogListDto3.getBuyerId());
			catalogStockListDto1.setOrderId(catalogListDto3.getPreOrderId());
			catalogStockListDto1.setProductId(catalogListDto3.getProductId());
			catalogStockListDto1.setCatalogId(catalogListDto3.getCatalogId());
			catalogStockListDto1.setActivityId(catalogListDto3.getActivityId());
			catalogStockListDto1.setSellerId(sellerId);
			catalogStockListDto1.setStockNum(catalogListDto3.getBuyCount());
			ProdStockCallService.ReturnStockListForRefundBill(Arrays.asList(catalogStockListDto1));
			//check
			ProdStockCallService.checkReturnStockForBill(catalogStockListDto1, catalogNum1, actNum1, true);
			
			//幂等
			ProdStockCallService.ReturnStockListForRefundBill(Arrays.asList(catalogStockListDto1),true,true);
			ProdStockCallService.checkReturnStockForBill(catalogStockListDto1, catalogNum1, actNum1, true);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReturnStockListForRefundBill_014() {
		Logger.start(true, "直播商品,没有限购,返库存");
		try {
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建直播");
			// 5分钟后开始200分钟后结束
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			//半小时之内会锁定不能修改
			Date starttime = new Date(now.getTime() + 60 * 60 * 1000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(clive);
			Logger.comment("加入商品");
			LiveRoomCallService.AddProductsToLive(createlive.getId(), sellerId, productId);
			Logger.comment("查询商品规格");
			YmtCatalogsIWapper CIWapper = new YmtCatalogsIWapper();
			List<String> cids = CIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			Logger.comment("创建秒杀活动");
			//CreateLiveActivityBean createliveactivityBean = LiveRoomCallService.initCreateLiveActivityBean(createlive.getId(), cids.get(0), 6d, 6, starttime);
			
			CreateLiveActivityBean createliveactivityBean = new CreateLiveActivityBean();
			LiveActivityDto LiveActivity=new LiveActivityDto();
			List<ActivityProductDto> ActivityProducts=new ArrayList<>();
			ActivityProductDto activityProductDto1 = new ActivityProductDto();
			activityProductDto1.setProductId(productId);
			activityProductDto1.setActivityPrice(7d);
			activityProductDto1.setActivityStock(100);
			activityProductDto1.setCatalogId(cids.get(0));
			ActivityProducts.add(activityProductDto1);
			
			LiveActivity.setActivityProducts(ActivityProducts);
			LiveActivity.setStartTime(String.valueOf(starttime.getTime()));
			LiveActivity.setEndTime(String.valueOf(starttime.getTime()+1*60*1000));
			LiveActivity.setLiveId(createlive.getId());
			LiveActivity.setSellerId(sellerId);
			createliveactivityBean.setLiveActivity(LiveActivity);
			
			createliveactivityBean.getLiveActivity().setActivityProducts(ActivityProducts);
			LiveRoomCallService.CreateLiveActivity(createliveactivityBean);
			
			LiveRoomWapper LiveRoomWapper = new LiveRoomWapper();
			//直播秒杀活动id
			Integer liveacctivityid = LiveRoomWapper.selectLiveactivityByLiveId(createliveactivityBean.getLiveActivity().getLiveId()).get(0).getLiveActivityId();
			Integer LiveActivityProductId = LiveRoomWapper.selectLiveactivityproduct(liveacctivityid, LiveActivity.getActivityProducts().get(0).getProductId()).get(0).getLiveActivityProductId();
			
			//更改活动时间
			String beginTime = YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMDTHMS_STRING);
			String endTime = YMTDateUtil.getBeforeOrNextDay(1, YMTDateUtil.YMDTHMS_STRING);
			UpdateProductActivityStockTimeBean updateProductActivityStockTimeBean = ProdStockCallService.initUpdateProductActivityStockTimeBean(sellerId, productId, liveacctivityid, 1, LiveActivityProductId, beginTime, endTime);
			ProdStockCallService.UpdateProductActivityStockTime(updateProductActivityStockTimeBean);
			Integer buyCount  = 10;
			// 扣库存
			PreOrderReduceCatalogDto preOrderReduceCatalogDto = ProdStockCallService.initPreOrderReduceCatalogDto(liveacctivityid, cids.get(0), buyCount);
			ProdStockCallService.ReduceStockListForPreOrder(preOrderReduceCatalogDto);
			//反库存
			long refundBillNo = getRefundBillNo();
			int buyerId = Math.abs(TestDataManager.getRandomIntNum(4));
			Long OrderID = System.currentTimeMillis();
			ArrayList<OrderReturnCatalogDtoV2> oList = new ArrayList<OrderReturnCatalogDtoV2>();
			OrderReturnCatalogDtoV2 orderReturnCatalogDto = new OrderReturnCatalogDtoV2();
			orderReturnCatalogDto.setRefundBillNo(refundBillNo);
			orderReturnCatalogDto.setBuyerId(buyerId);
			orderReturnCatalogDto.setOrderId(OrderID);
			orderReturnCatalogDto.setProductId(productId);
			orderReturnCatalogDto.setCatalogId(cids.get(0));
			orderReturnCatalogDto.setActivityId(liveacctivityid);
			orderReturnCatalogDto.setSellerId(sellerId);
			orderReturnCatalogDto.setStockNum(50);
			oList.add(orderReturnCatalogDto);
			returnStockListForRefundBillBean.setCatalogStockList(oList);
			returnStockListForRefundBillCall.setData(returnStockListForRefundBillBean);
			returnStockListForRefundBillCall.callService();
			//商品规格库存
			Integer catalogsNum = new YmtCatalogsIWapper().selectCatalogsByCatalogId(cids.get(0)).getiNum();
			//商品活动库存
			Integer istocknum = new YmtProductActivityStockWapper().selectByCatalogId(cids.get(0)).getIstocknum();
			Logger.verifyEquals(catalogNum-activityProductDto1.getActivityStock(), catalogsNum, "验证商品规格库存");
			Logger.verifyEquals(activityProductDto1.getActivityStock()-buyCount+orderReturnCatalogDto.getStockNum(), istocknum, "验证商品活动库存");
		
			//再次反库存
			returnStockListForRefundBillCall.callService();
			Logger.verifyEquals(catalogNum-activityProductDto1.getActivityStock(), catalogsNum, "验证商品规格库存");
			Logger.verifyEquals(activityProductDto1.getActivityStock()-buyCount+orderReturnCatalogDto.getStockNum(), istocknum, "验证商品活动库存");
		
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReturnStockListForRefundBill_015() {
		Logger.start(true, "普通现货商品,返库存");
		try{
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			// 扣库存
			Integer buyCount = 10;
			PreOrderReduceCatalogDto preOrderReduceCatalogDto = ProdStockCallService.initPreOrderReduceCatalogDto(0, catalogs.get(0), buyCount);
			ProdStockCallService.ReduceStockListForPreOrder(preOrderReduceCatalogDto);
			
			//返库存
			long refundBillNo = getRefundBillNo();
			int buyerId = Math.abs(TestDataManager.getRandomIntNum(4));
			Long OrderID = System.currentTimeMillis();
			ArrayList<OrderReturnCatalogDtoV2> oList = new ArrayList<OrderReturnCatalogDtoV2>();
			OrderReturnCatalogDtoV2 orderReturnCatalogDto = new OrderReturnCatalogDtoV2();
			orderReturnCatalogDto.setRefundBillNo(refundBillNo);
			orderReturnCatalogDto.setBuyerId(buyerId);
			orderReturnCatalogDto.setOrderId(OrderID);
			orderReturnCatalogDto.setProductId(productId);
			orderReturnCatalogDto.setCatalogId(catalogs.get(0));
			orderReturnCatalogDto.setActivityId(0);
			orderReturnCatalogDto.setSellerId(sellerId);
			orderReturnCatalogDto.setStockNum(50);
			oList.add(orderReturnCatalogDto);
			returnStockListForRefundBillBean.setCatalogStockList(oList);
			returnStockListForRefundBillCall.setData(returnStockListForRefundBillBean);
			returnStockListForRefundBillCall.callService();
			//商品规格库存
			Integer catalogsNum = new YmtCatalogsIWapper().selectCatalogsByCatalogId(catalogs.get(0)).getiNum();
			Logger.verifyEquals(catalogNum-buyCount+orderReturnCatalogDto.getStockNum(), catalogsNum, "验证商品规格库存");
			//返库存  幂等
			returnStockListForRefundBillCall.callService();
			Logger.verifyEquals(catalogNum-buyCount+orderReturnCatalogDto.getStockNum(), catalogsNum, "验证商品规格库存");
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReturnStockListForRefundBill_016() {
		Logger.start(true, "普通现货商品,删除规格返库存");
		try{
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			String catalogsId = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(0).getsCatalogId();
			// 扣库存
			Integer buyCount = 100;
			PreOrderReduceCatalogDto preOrderReduceCatalogDto = ProdStockCallService.initPreOrderReduceCatalogDto(0, catalogsId, buyCount);
			ProdStockCallService.ReduceStockListForPreOrder(preOrderReduceCatalogDto);
			 //已删除
			CIWapper.updateiActionByCatalogId(-1, catalogsId);
			//返库存
			long refundBillNo = getRefundBillNo();
			int buyerId = Math.abs(TestDataManager.getRandomIntNum(4));
			Long OrderID = System.currentTimeMillis();
			ArrayList<OrderReturnCatalogDtoV2> oList = new ArrayList<OrderReturnCatalogDtoV2>();
			OrderReturnCatalogDtoV2 orderReturnCatalogDto = new OrderReturnCatalogDtoV2();
			orderReturnCatalogDto.setRefundBillNo(refundBillNo);
			orderReturnCatalogDto.setBuyerId(buyerId);
			orderReturnCatalogDto.setOrderId(OrderID);
			orderReturnCatalogDto.setProductId(productId);
			orderReturnCatalogDto.setCatalogId(catalogsId);
			orderReturnCatalogDto.setActivityId(0);
			orderReturnCatalogDto.setSellerId(sellerId);
			orderReturnCatalogDto.setStockNum(50);
			oList.add(orderReturnCatalogDto);
			returnStockListForRefundBillBean.setCatalogStockList(oList);
			returnStockListForRefundBillCall.setData(returnStockListForRefundBillBean);
			returnStockListForRefundBillCall.callService();
			Integer getiNum = new YmtCatalogsIWapper().selectCatalogsByCatalogId(catalogsId).getiNum();
			Logger.verifyEquals(catalogNum-buyCount, getiNum,"验证商品规格库存");
			//返库存  幂等
			returnStockListForRefundBillCall.callService();
			Logger.verifyEquals(catalogNum-buyCount, getiNum,"验证商品规格库存");
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReturnStockListForRefundBill_017() {
		Logger.start(true, "普通现货商品,已删除规格不能扣减库存");
		try{
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			YmtCatalogsI ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			//删除规格
			CIWapper.updateiActionByCatalogId(-1, ymtCatalog.getsCatalogId());
			// 扣库存
			PreOrderReduceCatalogDto preOrderReduceCatalogDto = ProdStockCallService.initPreOrderReduceCatalogDto(0, catalogs.get(0), 100);
			ProdStockCallService.ReduceStockListForPreOrder(preOrderReduceCatalogDto);
			//返库存
			long refundBillNo = getRefundBillNo();
			int buyerId = Math.abs(TestDataManager.getRandomIntNum(4));
			Long OrderID = System.currentTimeMillis();
			ArrayList<OrderReturnCatalogDtoV2> oList = new ArrayList<OrderReturnCatalogDtoV2>();
			OrderReturnCatalogDtoV2 orderReturnCatalogDto = new OrderReturnCatalogDtoV2();
			orderReturnCatalogDto.setRefundBillNo(refundBillNo);
			orderReturnCatalogDto.setBuyerId(buyerId);
			orderReturnCatalogDto.setOrderId(OrderID);
			orderReturnCatalogDto.setProductId(productId);
			orderReturnCatalogDto.setCatalogId(catalogs.get(0));
			orderReturnCatalogDto.setActivityId(0);
			orderReturnCatalogDto.setSellerId(sellerId);
			orderReturnCatalogDto.setStockNum(50);
			oList.add(orderReturnCatalogDto);
			returnStockListForRefundBillBean.setCatalogStockList(oList);
			returnStockListForRefundBillCall.setData(returnStockListForRefundBillBean);
			returnStockListForRefundBillCall.callService();
			Integer getiNum = new YmtCatalogsIWapper().selectCatalogsByCatalogId(catalogs.get(0)).getiNum();
			Logger.verifyEquals(catalogNum, getiNum, "验证规格库存");
			//返库存  幂等
			returnStockListForRefundBillCall.callService();
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReturnStockListForRefundBill_018() {
		Logger.start(true, "活动商品,没有限购,返库存");
		try{
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"10");
			ProductManagerCallServiceV2.approveProductInActivity(productId, aids.get(0), true);
			Integer istocknum = new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(0)).getIstocknum();
			YmtCatalogsI ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			String catalogId = ymtCatalog.getsCatalogId();
			int stockNum = 20;
			
			int aid = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("aid").toString());
			String beginTime = YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMDTHMS_STRING);
			String endTime = YMTDateUtil.getBeforeOrNextDay(1, YMTDateUtil.YMDTHMS_STRING);
			
			//更改活动时间
			UpdateProductActivityStockTimeBean updateProductActivityStockTimeBean = ProdStockCallService.initUpdateProductActivityStockTimeBean(sellerId, productId, activityId, 0, Integer.valueOf(aids.get(0)), beginTime, endTime);
			ProdStockCallService.UpdateProductActivityStockTime(updateProductActivityStockTimeBean);
			// 扣库存
			ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId,sellerId, aid, stockNum, 0, true);
			//返库存
			long refundBillNo = getRefundBillNo();
			int buyerId = Math.abs(TestDataManager.getRandomIntNum(4));
			Long OrderID = System.currentTimeMillis();
			ArrayList<OrderReturnCatalogDtoV2> oList = new ArrayList<OrderReturnCatalogDtoV2>();
			OrderReturnCatalogDtoV2 orderReturnCatalogDto = new OrderReturnCatalogDtoV2();
			orderReturnCatalogDto.setRefundBillNo(refundBillNo);
			orderReturnCatalogDto.setBuyerId(buyerId);
			orderReturnCatalogDto.setOrderId(OrderID);
			orderReturnCatalogDto.setProductId(productId);
			orderReturnCatalogDto.setCatalogId(catalogId);
			orderReturnCatalogDto.setActivityId(activityId);
			orderReturnCatalogDto.setSellerId(sellerId);
			orderReturnCatalogDto.setStockNum(10);
			oList.add(orderReturnCatalogDto);
			returnStockListForRefundBillBean.setCatalogStockList(oList);
			returnStockListForRefundBillCall.setData(returnStockListForRefundBillBean);
			returnStockListForRefundBillCall.callService();
			Integer getiNum = new YmtCatalogsIWapper().selectCatalogsByCatalogId(catalogId).getiNum();
			Logger.verifyEquals(catalogNum-istocknum, getiNum, "验证规格库存");
			Integer istocknum2 = new YmtProductActivityStockWapper().selectByCatalogId(catalogId).getIstocknum();
			Logger.verifyEquals(istocknum-stockNum+orderReturnCatalogDto.getStockNum(), istocknum2, "验证规格库存");
			//返库存  幂等
			returnStockListForRefundBillCall.callService();
			Logger.verifyEquals(catalogNum-istocknum, getiNum, "验证规格库存");
			Logger.verifyEquals(istocknum-stockNum+orderReturnCatalogDto.getStockNum(), istocknum2, "验证规格库存");
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReturnStockListForRefundBill_019() {
		Logger.start(true, "活动商品,活动限购,扣减库存,返库存,扣库存");
		try{
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"10");
			ProductManagerCallServiceV2.approveProductInActivity(productId, aids.get(0), true);
			Integer istocknum1 = new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(0)).getIstocknum();
			YmtCatalogsI ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			String catalogId = ymtCatalog.getsCatalogId();
			int stockNum = 20;
			
			int aid = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("aid").toString());
			//修改活动限购数量 商品限购
			ProdStockCallService.updateActivityLimit(aid, 0, 40);
			//更改活动时间
			String beginTime = YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMDTHMS_STRING);
			String endTime = YMTDateUtil.getBeforeOrNextDay(1, YMTDateUtil.YMDTHMS_STRING);
			UpdateProductActivityStockTimeBean updateProductActivityStockTimeBean = ProdStockCallService.initUpdateProductActivityStockTimeBean(sellerId, productId, activityId, 0, Integer.valueOf(aids.get(0)), beginTime, endTime);
			ProdStockCallService.UpdateProductActivityStockTime(updateProductActivityStockTimeBean);
			// 扣库存
			ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId,sellerId, aid, stockNum, 0, true);
			//返库存
			long refundBillNo = getRefundBillNo();
			int buyerId = Math.abs(TestDataManager.getRandomIntNum(4));
			Long OrderID = System.currentTimeMillis();
			ArrayList<OrderReturnCatalogDtoV2> oList = new ArrayList<OrderReturnCatalogDtoV2>();
			OrderReturnCatalogDtoV2 orderReturnCatalogDto = new OrderReturnCatalogDtoV2();
			orderReturnCatalogDto.setRefundBillNo(refundBillNo);
			orderReturnCatalogDto.setBuyerId(buyerId);
			orderReturnCatalogDto.setOrderId(OrderID);
			orderReturnCatalogDto.setProductId(productId);
			orderReturnCatalogDto.setCatalogId(catalogId);
			orderReturnCatalogDto.setActivityId(activityId);
			orderReturnCatalogDto.setSellerId(sellerId);
			orderReturnCatalogDto.setStockNum(10);
			oList.add(orderReturnCatalogDto);
			returnStockListForRefundBillBean.setCatalogStockList(oList);
			returnStockListForRefundBillCall.setData(returnStockListForRefundBillBean);
			returnStockListForRefundBillCall.callService();
			
			Integer getiNum = new YmtCatalogsIWapper().selectCatalogsByCatalogId(catalogId).getiNum();
			Logger.verifyEquals(catalogNum-istocknum1, getiNum, "验证规格库存");
			Integer istocknum2 = new YmtProductActivityStockWapper().selectByCatalogId(catalogId).getIstocknum();
			Logger.verifyEquals(istocknum1-stockNum+orderReturnCatalogDto.getStockNum(), istocknum2, "验证活动库存");
			// 扣库存
			ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId,sellerId, aid, stockNum, 0, true);
			Logger.verifyEquals(catalogNum-istocknum1, getiNum, "验证规格库存");
			Logger.verifyEquals(istocknum1-stockNum+orderReturnCatalogDto.getStockNum(), istocknum2, "验证活动库存");
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReturnStockListForRefundBill_020() {
		Logger.start(true, "活动商品,活动商品限购,扣减库存,返库存,扣库存");
		try{
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"10");
			ProductManagerCallServiceV2.approveProductInActivity(productId, aids.get(0), true);
			Integer istocknum1 = new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(0)).getIstocknum();
			YmtCatalogsI ymtCatalog = ymtCatalogsIWapper.selectCatalogsByProductId(productId).get(0);
			String catalogId = ymtCatalog.getsCatalogId();
			int stockNum = 20;
			
			int aid = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("aid").toString());
			//修改活动限购数量 商品限购
			ProdStockCallService.updateActivityLimit(aid, 1, 40);
			//更改活动时间
			String beginTime = YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMDTHMS_STRING);
			String endTime = YMTDateUtil.getBeforeOrNextDay(1, YMTDateUtil.YMDTHMS_STRING);
			UpdateProductActivityStockTimeBean updateProductActivityStockTimeBean = ProdStockCallService.initUpdateProductActivityStockTimeBean(sellerId, productId, activityId, 0, Integer.valueOf(aids.get(0)), beginTime, endTime);
			ProdStockCallService.UpdateProductActivityStockTime(updateProductActivityStockTimeBean);
			// 扣库存
			ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId,sellerId, aid, stockNum, 0, true);
			//返库存
			long refundBillNo = getRefundBillNo();
			int buyerId = Math.abs(TestDataManager.getRandomIntNum(4));
			Long OrderID = System.currentTimeMillis();
			ArrayList<OrderReturnCatalogDtoV2> oList = new ArrayList<OrderReturnCatalogDtoV2>();
			OrderReturnCatalogDtoV2 orderReturnCatalogDto = new OrderReturnCatalogDtoV2();
			orderReturnCatalogDto.setRefundBillNo(refundBillNo);
			orderReturnCatalogDto.setBuyerId(buyerId);
			orderReturnCatalogDto.setOrderId(OrderID);
			orderReturnCatalogDto.setProductId(productId);
			orderReturnCatalogDto.setCatalogId(catalogId);
			orderReturnCatalogDto.setActivityId(activityId);
			orderReturnCatalogDto.setSellerId(sellerId);
			orderReturnCatalogDto.setStockNum(10);
			oList.add(orderReturnCatalogDto);
			returnStockListForRefundBillBean.setCatalogStockList(oList);
			returnStockListForRefundBillCall.setData(returnStockListForRefundBillBean);
			returnStockListForRefundBillCall.callService();
			Integer getiNum = new YmtCatalogsIWapper().selectCatalogsByCatalogId(catalogId).getiNum();
			Logger.verifyEquals(catalogNum-istocknum1, getiNum, "验证规格库存");
			Integer istocknum2 = new YmtProductActivityStockWapper().selectByCatalogId(catalogId).getIstocknum();
			Logger.verifyEquals(istocknum1-stockNum+orderReturnCatalogDto.getStockNum(), istocknum2, "验证活动库存");
			// 扣库存
			ProdStockCallService.ReduceStockListForPreOrder(productId, catalogId,sellerId, aid, stockNum, 0, true);
			Logger.verifyEquals(catalogNum-istocknum1, getiNum, "验证规格库存");
			Logger.verifyEquals(istocknum1-stockNum+orderReturnCatalogDto.getStockNum(), istocknum2, "验证活动库存");
			//返库存  幂等
			returnStockListForRefundBillCall.callService();
			Logger.verifyEquals(catalogNum-istocknum1, getiNum, "验证规格库存");
			Logger.verifyEquals(istocknum1-stockNum+orderReturnCatalogDto.getStockNum(), istocknum2, "验证活动库存");
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
		}catch(Exception e){
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReturnStockListForRefundBill_023() {
		Logger.start(true, "微信代购商品,渠道商,扣减库存,返库存");
		try{
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,rootUserName,true);
			Integer catalogNum = 10000;
			addAgentProductBean.getCatalogList().forEach(p->{
				p.setStock(catalogNum);
			});
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<YmtCatalogsI> ymtCatalogsIList = new YmtCatalogsIWapper().selectCatalogsByProductId(productId);
			int reduceNum = 10;
			PCatalogListDto catalogListDto = ProdStockCallService.ReduceStockListForPreOrder(productId, ymtCatalogsIList.get(0).getsCatalogId(), sellerId, 0, reduceNum, 0, true);
			ProdStockCallService.checkReduceStock(catalogListDto, catalogNum - reduceNum, 0);

			//反库存
			long refundBillNo = getRefundBillNo();
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDto = new OrderReturnCatalogDto.CatalogStockListDto();
			catalogStockListDto.setRefundBillNo(refundBillNo);
			catalogStockListDto.setBuyerId(catalogListDto.getBuyerId());
			catalogStockListDto.setOrderId(catalogListDto.getPreOrderId());
			catalogStockListDto.setProductId(productId);
			catalogStockListDto.setCatalogId(ymtCatalogsIList.get(0).getsCatalogId());
			catalogStockListDto.setSellerId(rootUserId);
			catalogStockListDto.setStockNum(reduceNum-1);
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDtoNew = ProdStockCallService.ReturnStockListForRefundBill(catalogStockListDto);
			//check
			ProdStockCallService.checkReturnStockForBill(catalogStockListDtoNew, catalogNum-1, 0, true);

			//幂等
			ProdStockCallService.ReturnStockListForRefundBill(Arrays.asList(catalogStockListDto),true,true);
			Thread.sleep(2000);
			ProdStockCallService.checkReturnStockForBill(catalogStockListDto, catalogNum-1, 0, true);

		}catch(Exception e){
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReturnStockListForRefundBill_021() {
		Logger.start(true, "微信代购商品,二级代理,扣减库存,返库存");
		try{
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,rootUserName,true);
			Integer catalogNum = 10000;
			addAgentProductBean.getCatalogList().forEach(p->{
				p.setStock(catalogNum);
			});
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			ImportAgentProductBean importAgentProductBean = AddAgentProductCallService.initImportAgentProduct(agentUserId1,agentUserName1,productId,rootUserId,false);

			String agentProductId = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean);
			int reduceNum = 10;
			List<YmtCatalogsI> ymtCatalogsIList = new YmtCatalogsIWapper().selectCatalogsByProductId(agentProductId);
			PCatalogListDto catalogListDto = ProdStockCallService.ReduceStockListForPreOrder(agentProductId, ymtCatalogsIList.get(0).getsCatalogId(), agentUserId1, 0, reduceNum, 0, true);
			YmtCatalogsI rootYmtCatalog = new YmtCatalogsIWapper().selectCatalogsByCatalogId(ymtCatalogsIList.get(0).getsCatalogId());
			//验证代理商库存为0
			ProdStockCallService.checkReduceStock(catalogListDto, 0, 0);

			catalogListDto.setCatalogId(rootYmtCatalog.getParentCatalogId());
			catalogListDto.setProductId(productId);
			//验证渠道商商品库存
			ProdStockCallService.checkReduceStock(catalogListDto, catalogNum - reduceNum, 0);

			//反库存
			long refundBillNo = getRefundBillNo();
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDto = new OrderReturnCatalogDto.CatalogStockListDto();
			catalogStockListDto.setRefundBillNo(refundBillNo);
			catalogStockListDto.setBuyerId(catalogListDto.getBuyerId());
			catalogStockListDto.setOrderId(catalogListDto.getPreOrderId());
			catalogStockListDto.setProductId(agentProductId);
			catalogStockListDto.setCatalogId(ymtCatalogsIList.get(0).getsCatalogId());
			catalogStockListDto.setSellerId(agentUserId1);
			catalogStockListDto.setStockNum(reduceNum-1);
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDtoNew = ProdStockCallService.ReturnStockListForRefundBill(catalogStockListDto);
			//check
			catalogStockListDto.setCatalogId(ymtCatalogsIList.get(0).getRootCatalogId());
			catalogStockListDto.setProductId(agentProductId);
			catalogStockListDto.setSellerId(agentUserId1);
			ProdStockCallService.checkReturnStockForBill(catalogStockListDtoNew, catalogNum-1, 0, true);

			//幂等
			ProdStockCallService.ReturnStockListForRefundBill(Arrays.asList(catalogStockListDto),true,true);
			ProdStockCallService.checkReturnStockForBill(catalogStockListDto, catalogNum-1, 0, true);

		}catch(Exception e){
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReturnStockListForRefundBill_022() {
		Logger.start(true, "微信代购商品,三级代理,扣减库存,返库存");
		try{
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(vipRootUserId,vipRootUserName,true);
			Integer catalogNum = 10000;
			addAgentProductBean.getCatalogList().forEach(p->{
				p.setStock(catalogNum);
			});
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			ImportAgentProductBean importAgentProductBean = AddAgentProductCallService.initImportAgentProduct(vipAgentUserId1,vipAgentUserName1,productId,vipRootUserId,true);
			importAgentProductBean.setSetAgentPrice(true);
			//渠道商->代理
			String agentProductId = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean);

			ImportAgentProductBean importAgentProductBean1 = AddAgentProductCallService.initImportAgentProduct(vipAgentUserId2,vipAgentUserName2,agentProductId,vipAgentUserId1,false);

			//渠道商->代理->代理
			String agentProductId1 = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean1);
			int reduceNum = 10;
			List<YmtCatalogsI> ymtCatalogsIList = new YmtCatalogsIWapper().selectCatalogsByProductId(agentProductId1);
			//扣减库存
			PCatalogListDto catalogListDto = ProdStockCallService.ReduceStockListForPreOrder(agentProductId1, ymtCatalogsIList.get(0).getsCatalogId(), vipAgentUserId2, 0, reduceNum, 0, true);
			//验证代理商2库存为0
			ProdStockCallService.checkReduceStock(catalogListDto, 0, 0);
			//代理商2的规格
			YmtCatalogsI agentYmtCatalog2 = new YmtCatalogsIWapper().selectCatalogsByCatalogId(ymtCatalogsIList.get(0).getsCatalogId());
			catalogListDto.setProductId(agentProductId);
			catalogListDto.setCatalogId(agentYmtCatalog2.getsCatalogId());
			catalogListDto.setSellerId(vipAgentUserId1);
			//验证代理商1的库存
			ProdStockCallService.checkReduceStock(catalogListDto, 0, 0);
			YmtCatalogsI agentYmtCatalog = new YmtCatalogsIWapper().selectCatalogsByCatalogId(ymtCatalogsIList.get(0).getRootCatalogId());
			catalogListDto.setProductId(productId);
			catalogListDto.setCatalogId(agentYmtCatalog.getsCatalogId());
			catalogListDto.setSellerId(vipRootUserId);
			//验证渠道商的库存
			ProdStockCallService.checkReduceStock(catalogListDto,catalogNum-reduceNum, 0);

			//返库存
			long refundBillNo = getRefundBillNo();
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDto = new OrderReturnCatalogDto.CatalogStockListDto();
			catalogStockListDto.setRefundBillNo(refundBillNo);
			catalogStockListDto.setBuyerId(catalogListDto.getBuyerId());
			catalogStockListDto.setOrderId(catalogListDto.getPreOrderId());
			catalogStockListDto.setProductId(agentProductId1);
			catalogStockListDto.setCatalogId(ymtCatalogsIList.get(0).getsCatalogId());
			catalogStockListDto.setSellerId(vipAgentUserId2);
			catalogStockListDto.setStockNum(reduceNum-1);
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDtoNew = ProdStockCallService.ReturnStockListForRefundBill(catalogStockListDto);

			//check
			catalogStockListDto.setCatalogId(ymtCatalogsIList.get(0).getRootCatalogId());
			catalogStockListDto.setProductId(productId);
			catalogStockListDto.setSellerId(vipRootUserId);
			ProdStockCallService.checkReturnStockForBill(catalogStockListDtoNew, catalogNum-1, 0, true);

			//幂等
			ProdStockCallService.ReturnStockListForRefundBill(Arrays.asList(catalogStockListDto),true,true);
			ProdStockCallService.checkReturnStockForBill(catalogStockListDto, catalogNum-1, 0, true);

		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReturnStockListForRefundBill_024() {
		Logger.start(true, "神器折扣，扣规格库存，返规格库存");
		try{
			//创建商品，设置初始库存，
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,rootUserName,false);
			Integer catalogNum11 = 10000;
			addAgentProductBean.getCatalogList().forEach(p->{
				p.setStock(catalogNum11);
			});
		 	String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
		 	//根据数据库查询
		 	ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(rootUserId,productId);
		 	System.out.println(selectProductDetails);
		 	//获取购买前商品规格库存
			Integer catalogNum = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(0).getiNum();
			System.out.println(catalogNum);
			//创建限时抢购活动
			List<String> catalogList =new ArrayList<String>();
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			AddactivityBean initProductaddactivity = AgentProductCallService.initProductaddactivity(rootUserId, productId, catalogList);
			int activityId = AgentProductCallService.agentProductaddactivity(initProductaddactivity);
			//减去5库存
			int reduceNum = 5;
			PCatalogListDto catalogListDto = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogList.get(0), rootUserId, activityId, reduceNum, 0, true);
			
			//获取商品规格库存
			Integer icatalogNum = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(0).getiNum();
			//获取活动库存
			ProductDetailsDto selectProductDetails1 = AddAgentProductCallService.selectProductDetails(rootUserId,productId);
			
			Logger.verifyEquals(9995, selectProductDetails1.getCatalogList().get(0).getStock(), "活动库存为0");
			Logger.verifyEquals(catalogNum, icatalogNum+5, "规格1库存验证");
			
			
			//返库存
			long refundBillNo = getRefundBillNo();
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDto = new OrderReturnCatalogDto.CatalogStockListDto();
			catalogStockListDto.setRefundBillNo(refundBillNo);
			catalogStockListDto.setBuyerId(catalogListDto.getBuyerId());
			catalogStockListDto.setOrderId(catalogListDto.getPreOrderId());
			catalogStockListDto.setProductId(productId);
			catalogStockListDto.setCatalogId(selectProductDetails.getCatalogList().get(0).getCatalogId());
			catalogStockListDto.setSellerId(vipAgentUserId2);
			catalogStockListDto.setStockNum(reduceNum-1);
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDtoNew = ProdStockCallService.ReturnStockListForRefundBill(catalogStockListDto);

			
			//获取商品规格库存
			Integer icatalogNum2 = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(0).getiNum();
			//获取活动库存
			ProductDetailsDto selectProductDetails2 = AddAgentProductCallService.selectProductDetails(rootUserId,productId);

			Logger.verifyEquals(9999, selectProductDetails2.getCatalogList().get(0).getStock(), "活动库存为0");
			
			Logger.verifyEquals(catalogNum, icatalogNum2+1, "规格1返还库存验证");
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ReturnStockListForRefundBill_025() {
		Logger.start(true, "神器折扣，扣完规格库存，再返规格库存");
		try{
			//创建商品，设置初始库存，
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,rootUserName,false);
			Integer catalogNum11 = 10;
			addAgentProductBean.getCatalogList().forEach(p->{
				p.setStock(catalogNum11);
			});
		 	String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
		 	//根据数据库查询
		 	ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(rootUserId,productId);
		 	System.out.println(selectProductDetails);
		 	//获取购买前商品规格库存
			Integer catalogNum = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(0).getiNum();
			System.out.println(catalogNum);
			//创建限时抢购活动
			List<String> catalogList =new ArrayList<String>();
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			AddactivityBean initProductaddactivity = AgentProductCallService.initProductaddactivity(rootUserId, productId, catalogList);
			int activityId = AgentProductCallService.agentProductaddactivity(initProductaddactivity);
			//减去5库存
			int reduceNum = 10;
			PCatalogListDto catalogListDto = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogList.get(0), rootUserId, activityId, reduceNum, 0, true);
			
			//获取商品规格库存
			Integer icatalogNum = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(0).getiNum();
			//获取活动库存
			ProductDetailsDto selectProductDetails1 = AddAgentProductCallService.selectProductDetails(rootUserId,productId);
			
			Logger.verifyEquals(0, selectProductDetails1.getCatalogList().get(0).getStock(), "活动库存为0");
			Logger.verifyEquals(catalogNum, icatalogNum+10, "规格1库存验证");
			
			
			//返库存
			long refundBillNo = getRefundBillNo();
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDto = new OrderReturnCatalogDto.CatalogStockListDto();
			catalogStockListDto.setRefundBillNo(refundBillNo);
			catalogStockListDto.setBuyerId(catalogListDto.getBuyerId());
			catalogStockListDto.setOrderId(catalogListDto.getPreOrderId());
			catalogStockListDto.setProductId(productId);
			catalogStockListDto.setCatalogId(selectProductDetails.getCatalogList().get(0).getCatalogId());
			catalogStockListDto.setSellerId(rootUserId);
			catalogStockListDto.setStockNum(reduceNum-1);
			OrderReturnCatalogDto.CatalogStockListDto catalogStockListDtoNew = ProdStockCallService.ReturnStockListForRefundBill(catalogStockListDto);

			
			//获取商品规格库存
			Integer icatalogNum2 = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(0).getiNum();
			//获取活动库存
			ProductDetailsDto selectProductDetails2 = AddAgentProductCallService.selectProductDetails(rootUserId,productId);

			Logger.verifyEquals(9, selectProductDetails2.getCatalogList().get(0).getStock(), "活动库存为0");
			
			Logger.verifyEquals(catalogNum, icatalogNum2+1, "规格1返还库存验证");
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	

	public static long getRefundBillNo(){
		return Long.parseLong(YMTDateUtil.getSysTime("yyyyMMddHHmmssSSS"));
//		return Long.parseLong(YMTDateUtil.getSysTime("HmmssSSS"));
	}

	public List<CatalogDto> setCatalogList(List<CatalogDto>	catalogDtos, int userId) throws IOException {
		listagentTypeBean listagentTypeBean = GodmchManageCallService.InitlistgentTypeBean(userId);
		List<AgentTypeVo> agentTypeVos = GodmchManageCallService.listgentTypeCall(listagentTypeBean).getAgentTypes();
		catalogDtos.forEach(p -> {
			List<AgentPriceDto> agentPriceDtos1 = new ArrayList<>();
			agentTypeVos.forEach(x -> {
				AgentPriceDto agentPriceDto = new AgentPriceDto();
				agentPriceDto.setAgentTypeId(x.getAgentType());
				double price = Double.parseDouble(1 + TestDataManager.getRandomNum(2));
				agentPriceDto.setAgentPrice(price);
				agentPriceDtos1.add(agentPriceDto);
			});
			p.setAgentPriceList(agentPriceDtos1);
		});
		return catalogDtos;
	}
	
}
